<?php 
namespace Wdl\model;
use Wdl\helper\FrontHelper;
use Wdl\helper\webHelper;

class house extends base{

    public function _query_sechouse_field(){
        return   ' id,title, 0+CAST(loyer AS CHAR) as loyer,traveaux_finition,donner_sur,area,quan,prix_unitaire,storey,
            superficie,total_storey,update_time,endtime,house_type,isonline,isdelete,company,broker_id,publish_name,employee,
            isjingpin,ishot,istop,show_jiaji,show_you,show_hight,disposition,zhutype,dong,ptype,danyuan, menpai,
            thumb,room,hall,garder,village_name,build_age ,rent_type,add_time,onclick,refresh_time,video ';
    }

    protected function condition()
    {
        $_GPC = $this->_GPC;
        $uniacid = $this->uniacid;
        $openid = $this->openid;
        /**/
        $search['keyword'] = trim($_GPC['keyword']);
        $search['area'] = trim($_GPC['area']);
        $search['quan'] = trim($_GPC['quan']);
        $search['minprice'] = intval($_GPC['minprice']);
        $search['maxprice'] = intval($_GPC['maxprice']);
        $search['sufix'] = trim($_GPC['sufix']);
        $search['minsufix'] = intval($_GPC['minsufix']);
        $search['maxsufix'] = intval($_GPC['maxsufix']);
        $search['room'] = trim($_GPC['room']);
        $search['isjingping'] = intval($_GPC['isjingping']);
        $search['istop'] = intval($_GPC['istop']);
        $search['ishot'] = intval($_GPC['ishot']);
        $search['village_id'] = intval($_GPC['village_id']);
        $search['village_name'] = trim($_GPC['village_name']);
        $search['order'] = intval($_GPC['order']);
        $search['chaoxiang'] = trim($_GPC['chaoxiang']);
        $search['disposition'] = trim($_GPC['disposition']);
        $search['hangye'] = trim($_GPC['hangye']);
        $search['danyuan'] = trim($_GPC['danyuan']);
        $search['zhuangxiu'] = trim($_GPC['zhuangxiu']);
        $search['morefind'] = $_GPC['morefind'];
        $zhutype = intval($_GPC['zhutype']);
        $rent_type = intval($_GPC['rent_type']);
        if (isset($_GPC['rent_type'])) {
            $rent_type = intval($_GPC['rent_type']);
        }
        /*不区分房源类型*/
        if(isset($_GPC['notype']) && $_GPC['notype']==1){
             $condition = " uniacid='$uniacid' and isonline=1 and isdelete=0 ";
             if(isset($_GPC['zhutype'])){
                  $condition .= "  and zhutype='$zhutype' ";
             }
             if(isset($_GPC['rent_type'])){
                  $condition .= "  and rent_type='$rent_type' ";
             }
        }else{ /*默认类型*/             
             $condition = " uniacid='$uniacid' and isonline=1 and isdelete=0 and zhutype='$zhutype' ";
             if($rent_type){
                $rent_type =  $rent_type==1 ? 0: 2;
                $condition.=" and   rent_type='$rent_type'";
             }
        }  
       
        /**/        
        /* 指定bid 表示查询经纪人的房源，isbroker =1 通过openid查询房源 这个是前端展示，不用于管理房源 */
        if (isset($_GPC['isbroker']) && $_GPC['isbroker'] == 1) {
            $brokerid = intval($_GPC['bid']);
            if ($brokerid > 0) {
                $condition = " uniacid='$uniacid' and broker_id='$brokerid' and rent_type='$rent_type' and zhutype in(0,1,2,3,7,8) and isonline=1 and isdelete=0 ";
            } else {
                $brokerid = pdo_fetchcolumn("select id from " . tablename("kbwdl_broker") . " where openid='$openid' and uniacid='$uniacid'");
                if ($brokerid > 0) {
                    $condition = " uniacid='$uniacid' and broker_id='$brokerid' and rent_type='$rent_type' and isonline=1 and isdelete=0  and zhutype in(0,1,2,3,7,8) ";
                } else {
                    $condition = " uniacid='$uniacid' and broker_name='$openid' and rent_type='$rent_type' and isonline=1 and isdelete=0  and zhutype in(0,1,2,3,7,8) ";
                }
            }
        }
        
        if (!empty($search['keyword'])) {
            $condition .= " and (`title` like '%{$search['keyword']}%' or `area` like '%{$search['keyword']}%' or `village_name` like '%{$search['keyword']}%')";
        }
        if(!empty($search['quan'])){
            $condition .= " and quan='{$search['quan']}'";
        }//有商圈按商圈搜索，否则按区域
        if (!empty($search['area']) && empty($search['quan'])) {
            $condition .= " and area='{$search['area']}'";
        }
        if (!empty($search['minprice'])) {
            $condition .= " and loyer>='{$search['minprice']}'";
        }
        if (!empty($search['maxprice'])) {
            $condition .= " and loyer<='{$search['maxprice']}'";
        }
        /**面积搜索 50-70,70-90,90-100,200-9999搜索值可能是这样*/
        if(!empty($search['sufix']) ){
            $sufixs = explode("-",$search['sufix']);
            $search['minsufix'] = $sufixs[0];
            $search['maxsufix'] = isset($sufixs[1]) ? $sufixs[1]:'';
            if(($sufixs = explode(",",$search['sufix']) ) && count($sufixs)>1 ){
               
                $search['maxsufix'] = explode("-",$sufixs[count($sufixs)-1 ])[1];
            }
           
        }
        
        if (!empty($search['minsufix'])) {
            $condition .= " and superficie>='{$search['minsufix']}'";
        }
        if (!empty($search['maxsufix'])) {
            $condition .= " and superficie<='{$search['maxsufix']}'";
        }
        /**小区搜索 */
        if (!empty($search['village_id'])) {
            $condition .= " and village_id='{$search['village_id']}'";
        }
        if (!empty($search['room'])) {
            $condition .= " and room  in ({$search['room']})";
        } 
        if ($search['isjingping'] == 1) {
            $condition .= " and isjingpin='{$search['isjingping']}'";
        }
        if(!empty($_GPC['bangtype']) && $_GPC['bangtype'] ==1){
            //捡漏榜
                $condition .= " and ishot > 0";
             
        }elseif(!empty($_GPC['bangtype']) && $_GPC['bangtype'] ==2){
            //必看榜单
            $condition .= " and isjingpin > 0";
        }
        
        if (!empty( $search['hangye']) ) {
            $condition .= " and prule like '%{$search['hangye']}%'";
        }
        if (!empty($search['danyuan'])) {
            $condition .= " and danyuan like '%{$search['danyuan']}%' ";
        }
        if (!empty($search['zhuangxiu'])) {
            $traveaux_finition = explode(",",$search['zhuangxiu'])[0];
            $condition .= " and traveaux_finition like '%{$traveaux_finition}%' ";
        }
        /**朝向搜索 */
        if(!empty($search['chaoxiang'])){
            $chaoxiang = explode(",", $search['chaoxiang']);
            $str = $dot = "";
            for($i=0; $i < count($chaoxiang); $i++){
                $str .= $dot. "'{$chaoxiang[$i]}'" ;
                $dot = ",";
            }
            if($str) 
                $condition .= " and donner_sur in ({$str})";
        }
        /**标签搜索处理 */
        if(!empty($search['disposition'])){
            $disposition = explode(",", $search['disposition']);
            $str = $dot = "";
            for($i=0; $i < count($disposition); $i++){
                $str .= $dot. " disposition like '%{$disposition[$i]}%'" ;
                $dot = " OR ";
            }
            if($str) 
                $condition .= " and ({$str}) ";
        }
        /**
         * 处理跟多搜索的情况
         */
        if(isset($_GPC['morefind']) && !empty($_GPC['morefind'])){
            $morefind = explode(',', trim(trim($_GPC['morefind'],']'), '[') );
            foreach($morefind as $k => $v){
                $morefind[$k] = trim($v,'&quot;');
            }
            /*户型*/
            if($morefind[0]){
                $condition .= " and room='{$morefind[0]}'";
            }/*类型 高层*/
            if($morefind[1]){
                $condition .= " and house_type='{$morefind[1]}'";
            }/*装修*/
            if($morefind[2]){
                $condition .= " and traveaux_finition='{$morefind[2]}'";
            }/*房龄*/
            if($morefind[3]){
                $years = date('Y');
                $tmp = array(
                    '1'=> " and ( build_age  <".$years." and build_age>".($years-2)." )",
                    '2'=> " and (build_age   <".($years-2)." and build_age>".($years-5).")",
                    '3'=> " and ( build_age   <".($years-5)." and build_age>".($years-10).")",
                    '4'=> " and ( build_age   <".($years-10)." and build_age>1980 )",
                );
                $condition .=  $tmp[$morefind[3]];
            }/*发布类型*/
            if($morefind[4]){
                if($morefind[4]==1){
                     $condition .= " and ptype='1' ";
                }else{
                    $condition .= " and ptype='0' "; 
                }
                
            }
            /*租房的类型*/
            if($morefind[5]>0){
                if($morefind[5]==1){
                     $condition .= " and danyuan='整租' ";
                }elseif($morefind[5]==2){
                    $condition .= " and danyuan='合租' "; 
                }else{}                
            } 
            if($morefind[6]>0){
                if($morefind[6]==1){
                     $condition .= " and dong='年租' ";
                }elseif($morefind[6]==2){
                    $condition .= " and dong='月租' "; 
                }elseif($morefind[6]==3){
                    $condition .= " and dong='日租' "; 
                }else{}                
            } 
            /*7 楼层*/
            if(isset($morefind[7]) && !empty($morefind[7])){
                $tmp = array(
                    '1-5'=> " and ( storey  < 6 and storey> 0 )",
                    '5-15'=> " and (storey   < 16 and storey> 5)",
                    '15-25'=> " and ( storey   < 26 and storey >15 )",
                    '25-35'=> " and ( storey   <200  and storey >25 )",
                );
               $condition .=  $tmp[$morefind[7]];
            }
            /*厂房和仓库 搜索 结构和 新旧程度*/
             if($morefind[8]){
                $condition .= " and danyuan='{$morefind[8]}'";
            }/*结构*/
             if($morefind[9]){
                $condition .= " and dong='{$morefind[9]}'";
            }/*新旧程度*/
        } 

        return $condition;
    }
    public function history(){
        FrontHelper::check_login();
        /* 分页参数 */
        $page = max(1, $this->_GPC['page']);
        $pagesize = isset( $this->_GPC['pagesize'])? $this->_GPC['pagesize'] : 10;
        $startlimit = ($page - 1) * $pagesize;  
        $fileds =  $this->_query_sechouse_field();
        $uniacid = $this->uniacid;
        $openid = $this->openid;
        $lasttime = strtotime("-1 years");
        $condition = " uniacid='$uniacid' and isonline=1 and isdelete=0 ";
        $condition.= " AND id in( select houseid from ".tablename('kbwdl_favorite')." where acttype='view' and openid='$openid' and addtime>'$lasttime' order by last_time desc ) ";
        $order = "refresh_time desc, update_time desc";
        $sql = "SELECT $fileds  FROM " . tablename("kbwdl_house") . " where $condition  order by $order limit $startlimit, $pagesize";
        $items = pdo_fetchall($sql);
        if (!empty($items)) {
            foreach ($items as $key => $item) {
                $val = $this->_format_sechouse($item);
                $items[$key] = $this->_format_show_item($val ) ;
            }
        }
        $data['total'] = pdo_fetchcolumn(" select count(*)  from ". tablename("kbwdl_house") . " where $condition ");
        $data['items'] = $items;
        $data['page'] = $page;
        $data['pagesize'] = $pagesize;
        return $this->msg(0, '我的收藏'.$sql, $data);
    }
    public function sechouse()
    { 
        /* 分页参数 */
        $page = max(1, $this->_GPC['page']);
        $pagesize = isset( $this->_GPC['pagesize'])? $this->_GPC['pagesize'] : 10;
        $startlimit = ($page - 1) * $pagesize;

        $condition = $this->condition();
        $fileds =  $this->_query_sechouse_field();
        /*排序*/       
        if($this->_GPC['order']>0){
            $tmp = array(1=>" add_time desc ", 2=> ' update_time desc ', 3=>' loyer desc','4'=>'istop desc,ishot desc ');
            $order = !empty($tmp[$this->_GPC['order']]) ? $tmp[$this->_GPC['order']] :"" ;            
        }
        if(empty($order)){
            $order = "refresh_time desc, update_time desc";
        }
        $sql = "SELECT $fileds  FROM " . tablename("kbwdl_house") . " where $condition  order by $order limit $startlimit, $pagesize";
        $items = pdo_fetchall($sql);

        if (!empty($items)) {
            foreach ($items as $key => $item) {
               //这个方法在wxapp.php文件内
                $val = $this->_format_sechouse($item);
                 /*经纪人*/
                    $val['groupid'] = 0;
                    if($val['iscompany']==9){
                        $val['pushtype'] = '个人';
                    }else{
                        $val['pushtype'] = '中介';
                    }
                    if($val['broker_id']>0){
                        $val['groupid'] = pdo_fetchcolumn("select groupid from ".tablename("kbwdl_broker"). " where id='".$val['broker_id']."'");
                        $val['pushtype'] = '经纪人';
                        if($val['groupid']==0){
                            $val['pushtype'] = '个人';
                        }
                    }  
                    /*求租求购获取发布人头像*/
                    if($val['zhutype']==4){
                        $tmp = pdo_fetch("select nickname,avatar from ".tablename("kbwdl_broker"). " where id='".$val['broker_id']."'");
                        if($tmp['avatar']=='undefined' || empty($tmp['avatar'])){
                            $tmp['avatar'] = 'addons/kbwdl_shequzufang/style/images/house_face.jpg';
                        }
                        $tmp['avatar'] = toimage($tmp['avatar']);
                        $val['sendbroker'] = $tmp;
                         
                    }
               //这个方法在wxapp.php文件内
               $items[$key] = $this->_format_show_item($val ) ;
             }
        }
        $data['total'] = pdo_fetchcolumn(" select count(*)  from ". tablename("kbwdl_house") . " where $condition ");
        $data['items'] = $items;
        $data['page'] = $page;
        $data['pagesize'] = $pagesize;
        return $this->msg(0, '二手房列表'.$sql, $data);
    }
        /*格式化输出参数到前端模板*/
        public  function _format_show_item($val , $ischarges=0, $groupid=0){
            $val['ischarges'] = $ischarges;
            $val['groupid'] = $groupid;
            /*默认房源类型的列表页 是二手房*/
            $val['moreurl'] = "../house/search?type=2";
            if( $val['zhutype']==0 || $val['zhutype'] ==3 ){            
                /*二手房 和新房*/
                $val['item_address'] = $val['room'].'房'. $val['hall'].'厅/'. 
                        $val['superficie'].'㎡/'. $val['donner_sur'] .
                        '/'.$val['storey'] ;
                $val['item_price'] =  $val['loyer'] .  $val['prix_unitaire'];
                $val['item_per'] =    $val['perprice'] ? ($val['perprice'] .  $val['perprice_unit']) : '';
                $val['quan'] = $val['quan'] ? $val['quan'] : $val['village_name'];
                if($val['quan'] =='-'){
                     $val['quan'] =  $val['village_name'];
                }
                $val['item_area'] =  $val['area'] .' '. $val['quan'] ;
                 $val['item_time'] = '';
                $val['showtag'] = 1; /*显示标签*/
                if($ischarges==1){ /*分销处理*/
                    if($groupid==0){
                        $val['price_label'] = '售价';
                    }else{
                       $val['price_label'] = '佣'; 
                       $val['item_price'] = $val['employee'] ? $val['employee'] : $val['item_price'];
                    }
                }
               
            }else if( $val['zhutype']== 2){
                 $val['moreurl'] = "../house/zhu?rent=2&zhutype=2";
                /*租房*/
                $val['item_address'] = $val['room'].'房'. $val['hall'].'厅 / '. $val['superficie'].'㎡   ' ;
                $val['item_price'] =  $val['loyer'] .  $val['prix_unitaire'];
                $val['item_per'] =   '';/*  $val['menpai'];*/
                $val['quan'] = $val['quan'] ? $val['quan'] : $val['village_name'];
                if($val['quan'] =='-'){
                     $val['quan'] =  $val['village_name'];
                }
                $val['item_area'] =  $val['area'] .' '. $val['quan'] ;
                 $val['item_time'] = '';
                 $val['showtag'] = 1; /*显示标签*/
                if($ischarges==1){ /*分销处理*/
                    if($groupid==0){
                        $val['price_label'] = '租金';
                    }else{
                       $val['price_label'] = '佣'; 
                       $val['item_price'] = $val['employee'] ? $val['employee'] : $val['item_price'];
                    }
                }
            }else if( $val['zhutype']==9){
                 $val['moreurl'] = "../house/xie?rent=".$val['rent_type']."&zhutype=1";
                /*写字楼 */
                $val['item_address'] = $val['area'].'  '. $val['quan'] .'  '.  $val['superficie'].'㎡   ' ;
                $val['item_price'] =  $val['loyer'] .  $val['prix_unitaire'];
                $val['item_per'] =   ''  ; 
               
                $val['item_area'] =   $val['village_name'];
                $val['item_time'] =   $val['perprice'] ? ($val['perprice'] .  $val['perprice_unit']) : '';
                if($val['rent_type']==0){
                    $val['item_time'] = '单价 '.$val['item_time'] ;
                }else{
                     $val['item_time'] = '租金 '.$val['item_time'] ;
                }
                $val['showtag'] = 0; /*显示时间*/
            }else if( $val['zhutype']==4){

                if($val['rent_type'] == 0 || $val['rent_type']== 2 ){
                    $val['moreurl'] = "../house/sp?rent=".$val['rent_type']."&zhutype=2";
                    /*商铺 */
                    $val['item_address'] =  $val['area'].$val['quan'] .'  '.  $val['superficie'].'㎡   ' ;
                    $val['item_price'] =  $val['loyer'] .  $val['prix_unitaire'];
                    $val['item_per'] =   ''  ; 
                
                    $val['item_area'] = $val['village_name'];
                    $val['item_time'] =   $val['perprice'] ? ($val['perprice'] .  $val['perprice_unit']) : '';
                    if($val['rent_type']==0){
                        $val['item_time'] = '单价 '.$val['item_time'] ;
                    }else{
                        $val['item_time'] = '租金 '.$val['item_time'] ;
                    }
                    $val['showtag'] = 0; /*显示时间*/
                    if($ischarges==1){ /*分销处理*/
                        if($groupid==0){
                            $val['price_label'] = '售价';
                        }else{
                        $val['price_label'] = '佣'; 
                        $val['item_price'] = $val['employee'] ? $val['employee'] : $val['item_price'];
                        }
                    }
                }else {
                    $val['moreurl'] = "../house/syi?rent=".$val['rent_type']."&zhutype=3";
                    /*生意转让 */
                    $val['item_address'] = $val['area'].'  '. $val['quan'].  $val['superficie'].'㎡   ' ;
                    $val['item_price'] =  $val['loyer'] .  $val['prix_unitaire'];
                    $val['item_per'] =   '转让费 '.$val['dong'].'万'  ; 
                
                    $val['item_area'] =   $val['village_name'];
                    $val['item_time'] =   $val['perprice'] ? ($val['perprice'] .  $val['perprice_unit'])  : '';
                    $val['item_time'] = '租金'. $val['item_time'];
                    $val['showtag'] = 0; /*显示时间*/
                }
            }else if( $val['zhutype']==5){
                /*求租求购 */
                $val['item_address'] = $val['village_name']  ;
                $val['item_price'] =  $val['tags'][1]  ;
                $val['item_per'] =    '面积：'.$val['tags'][0]   ; 
               
                $val['item_area'] =  $val['area'].'  '. $val['quan'] ;
                $val['item_time'] =   $val['perprice'] ? ($val['perprice'] .  $val['perprice_unit'])  : '';
                $val['item_time'] =  $val['room'].'房'. $val['hall'].'厅'. $val['garden'].'卫  ' ;
                $val['showtag'] = 0; /*显示时间*/
            }else if($val['zhutype'] ==7){
                /*厂房*/
                     $val['moreurl'] = "../house/xie?rent=".$val['rent_type']."&zhutype=7";
                /*写字楼 */
                $val['item_address'] = $val['area'].'  '. $val['quan'] .'  '.  $val['superficie'].'㎡   ' ;
                $val['item_price'] =  $val['loyer'] .  $val['prix_unitaire'];
                $val['item_per'] =   ''  ; 
               
                $val['item_area'] =   $val['village_name'];
                $val['item_time'] =   $val['perprice'] ? ($val['perprice'] .  $val['perprice_unit']) : '';
                if($val['rent_type']==0){
                    $val['item_time'] = '售价 '.$val['item_time'] ;
                }else{
                     $val['item_time'] = '租金 '.$val['item_time'] ;
                }
            } else if($val['zhutype'] == 8){
                /*仓库*/
                     $val['moreurl'] = "../house/xie?rent=".$val['rent_type']."&zhutype=7";
                /*仓库 */
                $val['item_address'] = $val['area'].'  '. $val['quan'] .'  '.  $val['superficie'].'㎡   ' ;
                $val['item_price'] =  $val['loyer'] .  $val['prix_unitaire'];
                $val['item_per'] =   ''  ; 
               
                $val['item_area'] =   $val['village_name'];
                $val['item_time'] =   $val['perprice'] ? ($val['perprice'] .  $val['perprice_unit']) : '';
                if($val['rent_type']==0){
                    $val['item_time'] = '售价 '.$val['item_time'] ;
                }else{
                     $val['item_time'] = '租金 '.$val['item_time'] ;
                }
            }
           return $val; 
        }
        /**
     * 格式化二手房房源
     * @param type $val
     */
    public function _format_sechouse($item) {
        $val = $item;
        if (empty($val['thumb'])) {
            $val['thumb'] = 'addons/kbwdl_shequzufang/style/images/house_face.jpg';
        }
        if((!strpos($val['thumb'],'mages') ) && (!strpos($val['thumb'],'weihouse'))){
            $val['thumb'] = 'addons/kbwdl_shequzufang/style/images/house_face.jpg';
        }
        $val['thumb'] = toimage($val['thumb']);

	    $s = max(1,$val['superficie'] ); 
            
       if($val['loyer']==0){
             $val['loyer'] =  '面议' ;
             $val['prix_unitaire'] = '';
             $val['first_price'] = '-';
             $val['perprice'] = '-';
        }else{
            $val['prix_unitaire'] = rtrim($val['prix_unitaire'], '元');
            $val['perprice'] = '-';
            $val['first_price'] =  "-";
            if(is_numeric($val['loyer'])){
                $val['perprice'] =  ceil($val['loyer']*10000 / $s);                
                $val['first_price'] = ceil($val['loyer']*40/100); 
            } 
        } 
        /**二手房 */
        if($val['zhutype']==0){
            $val['danyuan'] = $val['danyuan'] ? $val['danyuan']."%": '面议';
        }
        $val['infolabel'] = webHelper::zhutypeLabel($val['zhutype']);
        $val['infotype'] =  $val['rent_type']==2? '出租': '出售';
        
         $pl = [0=> '售价',2=> '租金',3=> '租金'];
         $val['price_label'] =  isset($pl[$val['rent_type']]) ? $pl[$val['rent_type']] : '价格';
        /*日租房*/
        if(  $val['zhutype']==2 ){
            if($val['dong']=='日租'){
                if(is_numeric($val['loyer'])){
                    $val['prix_unitaire'] = '元/日'; 
                }
            }
            if( $val['dong']=='年租'){
                if(is_numeric($val['loyer'])){
                    $val['prix_unitaire'] = '元/年'; 
                }
            } 
              /*租房 押金*/
            $val['danyuan'] = empty($val['danyuan'])? '整租':$val['danyuan'];
            $val['dong'] = empty($val['dong'])? '月租':$val['dong'];  
            $val['infotype'] = $val['dong'];   
        }
       
        /*$val['perprice'] = '-';*/
        $val['perprice_unit'] = '元/㎡';
        /*如果是写字楼，商铺 ，生意 算出的是 元/㎡/月*/
        if($val['rent_type']==2 && ($val['zhutype'] <4)){
             if(is_numeric($val['loyer'])){
                $val['perprice'] = number_format($val['loyer'] / $s, 2);
             } 
            $val['perprice_unit'] =  '元/㎡/月' ;
        }
        /*厂房出租*/
       if($val['rent_type']==2 && ($val['zhutype'] ==7 ) ||  ($val['zhutype'] ==8 ) ){
          /*厂房仓库出租*/
           
            if($val['prix_unitaire'] =='元/月'){
                if(is_numeric($val['loyer'])){
                    $val['perprice'] = number_format($val['loyer'] / $s, 2);
                 } 
                 $val['perprice_unit'] = $val['prix_unitaire'] ."/㎡";
            }               
            else{
                $val['perprice_unit'] = $val['prix_unitaire'];
            }
            
        }   
       
       if($val['rent_type']==0 ){
           if($this->app->module['config']['system']['layertype']==2){
               $val['storey'] = $val['storey'].'层';
           }else{
            /*二手房 楼层*/
            $storey = intval($val['storey']);
            $mid =  max($val['total_storey'],6) /2;
           if($storey>0){
             $val['storey'] = '低层';
             }
              if($storey>($mid-2)){
                 $val['storey'] = '中层';
             }
              if($storey>($mid+2)){
                 $val['storey'] = '高层';
             } 
           }
       }
       /**商铺 */
        if( $val['zhutype']==4 ){
            $val['infotype'] =   '出售';
             
              /*商铺出租*/
            if($val['rent_type']==2 ){
                if(is_numeric($val['loyer'])){
                    $val['perprice'] = number_format($val['loyer'] / $s,2 );
                }
               $val['perprice_unit'] = $val['prix_unitaire'].'/㎡';
               $val['infotype'] =   '出租';

            }
              
            /*生意租转*/
      
            if($val['rent_type']== 3){
                if(is_numeric($val['loyer'])){
                    $val['perprice'] =  number_format ($val['loyer'] / $s /30,2) ;
                 }
                $val['perprice_unit'] = '元/㎡/天';
                $val['infotype'] =   '转让';
                if(empty($val['dong'])){
                    $val['dong'] = '面议';
                }else{
                     $val['dong'] =  $val['dong'];
                }
            }
          
       }
       
        /*首付比例*/
        $perbill = $val['qq']? intval($val['qq']): 40;
        $val['bill'] = $perbill;
        $val['billpay'] = intval($val['loyer'] )* $perbill/100;
    
        $val['quan'] = $val['quan'] ? $val['quan'] : '-';
	
        $val['refresh_time'] = $val['refresh_time'] ? $val['refresh_time'] : $val['add_time'];
        if ($val['refresh_time'] > $val['add_time']) {
            $val['add_time'] = $val['refresh_time'];
        }
        $val['add_time'] = date('Y-m-d H:i', $val['add_time']);
        $val['refresh_time'] = date('Y-m-d H:i', $val['refresh_time']);
        /* 标签 */
        $tags = $val['disposition'];
        $val['tags_all'] = 
        $val['tags'] =   array( $val['infotype'],$val['house_type'] ?$val['house_type']:'' );
        $tag = [];
        if(!empty($tags)){
            $tag = explode(",", $tags);
            $val['tags_all'] = $tag;
            $tmp = array();     
            $tnums = $val['isjingpin']==1? 2: 3;        
                foreach($tag as $kk=> $vv){
                    if( $kk> $tnums ){ break; }
                    if(!empty($vv)){
                        array_push($tmp, $vv);
                    }
             }
            $val['tags'] = $tmp;
        }
        /**租房的配套和 */
        if($val['zhutype'] == 2){
            $val['peitao'] = FrontHelper::chuzu_tags($val['disposition']);
        }
        /*厂房和 仓库 的标签 显示 类型和 */
         if($val['zhutype']==7 || $val['zhutype']==8){
            $val['tags'] = [$val['house_type'], $val['danyuan'],$val['dong'] ];  
            //$val['perprice'] = '';
            $cg = [ "单层", "多层","立体","简仓","露天"];
            if(isset($cg[$val['storey']])){
                $val['storey'] = $cg[$val['storey']];
            }
            
         }
        if ($val['zhutype'] == '3') {
            /* 生意转让 */
            $tmp = explode(',', $val['disposition']);
            $val['hangye'] = $tmp[0];
            $val['jingyin'] = $tmp[1];
        }
        $val['helpinfo'] = '温馨提示：请去电时说明在《'.$this->app->module['config']['shopname'].'》上看到，谢谢！';
       
        /*发布类型*/
        $val['pushtype'] = $val['ptype']==1? '个人': '中介';
        /*开启所有电话统一*/
        if($this->app->module['config']['isallphone']==1){
            $val['linkphone'] = $this->app->module['config']['phone'];
            $val['broker']['mobile'] = $val['linkphone'];
        }
        /*佣金*/
        if(empty($val['employee'])){
            $val['employee'] = '';
        }
        return $val;
    }
}